<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>后台</title>
<link rel="icon" href="/favicon.ico" type="image/x-icon" />
<link rel="bookmark" href="/favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
<meta
	content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
	name="viewport">
<link rel="stylesheet" href="/dist/css/bootstrap/bootstrap.min.css">
<link rel="stylesheet"
	href="https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.css">
<link rel="stylesheet"
	href="https://cdn.bootcss.com/ionicons/2.0.1/css/ionicons.min.css">
<link rel="stylesheet" href="/dist/css/adminlte/AdminLTE.min.css">
<link rel="stylesheet" href="dist/css/skins/skin-blue.min.css">
<link rel="stylesheet" type="text/css" href="/dist/easyui/themes/gray/easyui.css">

</head>
<script src="/dist/plugins/jQuery/jquery-2.2.3.min.js"></script>
<script src="/dist/js/bootstrap.min.js"></script>
<script src="/dist/js/app.min.js"></script>
<script src="https://cdn.bootcss.com/layer/3.0.1/layer.min.js"></script>
<script type="text/javascript" src="/dist/easyui/jquery.easyui.min.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.1.1.js"></script>
<script type="text/javascript">
	$(document)
			.ready(
					function() {
						var _toolbar = [ {
							id : 'btnRefresh',
							text : '刷新',
							iconCls : 'icon-reload',
							handler : function() {
								refresh();
							}
						}, '-', {
							id : 'btnAddItem',
							iconCls : 'icon-add',
							text : '添加',
							handler : function() {
								add();
							}
						} ];
						$('#datagrid')
								.datagrid(
										{
											title : '任务调度管理',
											url : '/jobmanage/post',
											toolbar : _toolbar,
											columns : [ [
													{
														field : 'id',
														title : 'ID',
														width : 50,
														align : 'center'
													},
													{
														field : 'name',
														title : '任务名',
														width : 100,
														align : 'center'
													},
													{
														field : 'group',
														title : '任务组名',
														width : 100,
														align : 'center'
													},
													{
														field : 'clazz',
														title : '类全名',
														width : 300,
														align : 'center'
													},
													{
														field : 'cron_expression',
														title : '定时表达式',
														width : 100,
														align : 'center'
													},
													{
														field : 'is_enabled',
														title : '是否启动',
														width : 100,
														align : 'center'
													},
													{
														field : 'action',
														title : '操作',
														width : 150,
														align : 'center',
														formatter : function(
																value, row,index) {
															
															var a = "<a href='javascript:update("+row.id+")'>修改</a> ";
											        		var b = "<a href='javascript:deleteItem("+row.id+")'>启停</a>";
								                            return a + "   " +b;
														}
													} ] ],
											pagination : true,
											rownumbers : true,
											pageSize : 20,
											rowStyler : function(index, row) {
												return "height:100px;";
											},
											singleSelect : true
										});
						$(document).on("click", ".addSubmitBtn", addSubmit);
						$(document).on("click", ".updateBtn", update);
						$(document).on("click", ".delBtn", deleteItem);
					});
	/* 刷新 */
	function refresh() {
		$('#datagrid').datagrid('reload');
	}
	/* 添加 */
	function add() {
		$("#showAddId").hide();
		$("#myModalLabel").text("新增");
		$("#add_id").val("");
		$("#add_name").val("");
		$("#add_group").val("");
		$("#add_clazz").val("");
		$("#add_cron_expression").val("");
		$("#add_is_enabled").val("");
		$("#myModal").modal("show");
	}
	/* 更新 */
	function update(id) {
		console.log("update");
		/* var id = $(this).data("id"); */
		var id = id;
		$("#myModalLabel").text("修改");
		$.post("/jobmanage/get", {
			id : id
		}, function(data) {
			if (data.result == "success") {
				$("#add_id").val(data.data.id);
				$("#add_name").val(data.data.name);
				$("#add_group").val(data.data.group);
				$("#add_clazz").val(data.data.clazz);
				$("#add_cron_expression").val(data.data.cron_expression);
				$("#add_is_enabled").val(data.data.is_enabled);
			} else {
				alert(data.message);
			}
		});
		$("#showAddId").show();
		$("#myModal").modal("show");
	}
	/* 添加修改提交 */
	function addSubmit() {
		var req_params = {};
		req_params.id = $("#add_id").val();
		req_params.name = $("#add_name").val();
		req_params.group = $("#add_group").val();
		req_params.clazz = $("#add_clazz").val();
		req_params.cron_expression = $("#add_cron_expression").val();
		req_params.is_enabled = $("#add_is_enabled").val();
		$.post('/jobmanage/add', req_params, function(data) {
			if (data.result == "success") {
				var title = $("#myModalLabel").text();
				layer.msg(title + "完成");
				$("#myModal").modal("hide");
				refresh();
			} else {
				alert(data.message);
			}
		});
	}
	/* 删除 */
	function deleteItem(id) {
		/* var id = $(this).data("id"); */
		if (!window.confirm("确认启停")) {
			return;
		}
		$.post("/jobmanage/delete", {
			id : id
		}, function(data) {
			if (data.result == "success") {
				layer.msg("启停完成");
				refresh();
			} else {
				alert(data.message);
			}
		});
	}
	/* 搜索 */
	function search() {
		var id = $('#search_id').val();
		var name = $('#search_name').val();
		var group = $('#search_group').val();
		var is_enabled = $('#search_is_enabled').val();
		$('#datagrid').datagrid('load', {
			"id" : id,
			"name" : name,
			"group" : group,
			"is_enabled" : is_enabled
		});
	}
</script>

<body>

	<div id="p1" class="easyui-panel" title="查询"
		style="padding: 10px; background: #fafafa; margin-bottom: 10px;"
		iconCls="icon-sum" closable="false" collapsible="false" minimizable="false"
		maximizable="false">
		ID:<input id="search_id" name="search_id"
			class="txt_fm_mmp easyui-validatebox search"> 任务名:<input
			id="search_name" name="search_name"
			class="txt_fm_mmp easyui-validatebox search"> 任务组名:<input
			id="search_group" name="search_group"
			class="txt_fm_mmp easyui-validatebox search"> 是否启动:<input
			id="search_is_enabled" name="search_is_enabled"
			class="txt_fm_mmp easyui-validatebox search"> <a
			href="javascript:search();" class="easyui-linkbutton" plain="true"
			iconCls="icon-search">搜索</a>
	</div>

	<table id="datagrid"></table>


	<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel" data-backdrop="false">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title" id="myModalLabel">新增</h4>
				</div>
				<div class="modal-body">
					<form class="form-horizontal">
						<div class="form-group" style="display: none" id="showAddId">
							<label for="add_id" class="col-sm-2 control-label">id</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="add_id" placeholder="ID"
									readonly>
							</div>
						</div>
						<div class="form-group">
							<label for="add_name" class="col-sm-2 control-label">任务名</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="add_name" placeholder="任务名"
									required>
							</div>
						</div>
						<div class="form-group">
							<label for="add_group" class="col-sm-2 control-label">任务组名</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="add_group"
									placeholder="任务组名" required>
							</div>
						</div>
						<div class="form-group">
							<label for="add_clazz" class="col-sm-2 control-label">类全名</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="add_clazz" placeholder="类全名"
									required>
							</div>
						</div>
						<div class="form-group">
							<label for="add_cron_expression" class="col-sm-2 control-label">定时表达式</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="add_cron_expression"
									placeholder="定时表达式" required>
							</div>
						</div>
						<div class="form-group" hidden="true">
							<label class="col-sm-2 control-label">是否启动</label>
							<div class="col-sm-10">
								<select class="form-control" id="add_is_enabled">
									<option value="N">否</option>
									<option value="Y">是</option>
								</select>
							</div>
						</div>
					</form>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
					<button type="button" class="btn btn-primary addSubmitBtn">提交</button>
				</div>
			</div>
		</div>
	</div>


</body>
</html>